/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package seso;

import java.awt.*;
import java.awt.geom.RoundRectangle2D;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.JLabel;

/**
 *
 * @author Administrator
 */
public class RTable extends javax.swing.JTable {
    
    private Color tableHeaderBGColor = new Color(114,158,191);

    public RTable() {
        super();

        setFont(new Font("Arial Unicode MS", Font.PLAIN, 11));
        setRowHeight(20);
        getTableHeader().setBackground(tableHeaderBGColor);        
        
        setBorder(null);
        setFillsViewportHeight(true);
    }

    @Override
    protected void paintComponent(Graphics g) {
        
        if (java.beans.Beans.isDesignTime()) {
            super.paintComponent(g);
            return;
        }
        
        refreshRender();
        super.paintComponent(g);
        
        if (getRootPane().getParent() instanceof MaintDialog) {
            ((MaintDialog)(getRootPane().getParent())).refreshTableHeaderField();
        }
    }


    public void refreshRender() {
            RHeaderCellRenderer renderer;
            TableColumnModel colModel = getColumnModel();
            
            for (int i = 0; i < colModel.getColumnCount(); i++) {
                renderer = new RHeaderCellRenderer();
                colModel.getColumn(i).setHeaderRenderer(renderer);
            }
    }
    
    public void setRowFilter(String filter) {
        TableModel tm = this.getModel();
        TableRowSorter sorter = new TableRowSorter(tm);
        sorter.setRowFilter(RowFilter.regexFilter(filter));
        this.setModel(tm);
        this.setRowSorter(sorter);
    }
}

class RHeaderCellRenderer implements TableCellRenderer {

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
            boolean hasFocus, int row, int column) {

        if (java.beans.Beans.isDesignTime()) {
            return (new javax.swing.JLabel(value.toString()));
        }

        RTableHeaderLabel rTableHeaderLabel = new RTableHeaderLabel();

        rTableHeaderLabel.setHeaderText(value.toString());

        return rTableHeaderLabel;

    }
}
